@extends('admin.layouts.wap_simple')
@section('title', '开始转正小程序')
@section('content')
<meta name="csrf-token" content="{{ csrf_token() }}">
<div class="main-back">
    <div class="m-card">
        <div class="m-form-child-title">
            <label>企业信息:</label>
            <div onclick="multiplex();">
                <font>复用小程序注册信息模版</font>
                <i class="bx bx-chevrons-up"></i>
            </div>
        </div>
        <div class="m-form-child m-col-12 m-xs-12">
            <div class="m-form-item">
                <label><b>*</b>转正企业名称:</label>
                <div class="m-col-12">
                    <input type="text" class="m-input" id="enterprise_name" placeholder="企业名（需与工商部门登记信息一致)" maxlength="30" value="">
                </div>
            </div>
            <div class="m-form-item">
                <label><b>*</b>统一社会信用代码</label>
                <div class="m-col-12">
                    <input type="text" class="m-input" id="code" placeholder="请输入企业代码" maxlength="18" value="">
                </div>
            </div>
        </div>

        <div class="m-form-child-title">
            <label>法人信息:</label>
        </div>
        <div class="m-form-child m-col-12 m-xs-12">
            <div class="m-form-item">
                <label><b>*</b>法人微信号:</label>
                <div class="m-col-12">
                    <input type="text" class="m-input" id="legal_persona_wechat" placeholder="法人微信号" maxlength="30" value="">
                </div>
            </div>
            <div class="m-form-item">
                <label><b>*</b>法人姓名</label>
                <div class="m-col-12">
                    <input type="text" class="m-input" id="legal_persona_name" placeholder="请输入法人姓名" maxlength="18" value="">
                </div>
            </div>
            <div class="m-form-item">
                <label><b>*</b>法人身份证号</label>
                <div class="m-col-12">
                    <input type="text" class="m-input" id="legal_persona_idcard" placeholder="请输入法人身份证号" maxlength="18" value="">
                </div>
            </div>
        </div>

        <div class="m-form-item">
            <div class="m-form-btn m-mr-1" onclick="verifyBetaWeapp();">立即转正小程序</div>
        </div>
    </div>
</div>
<div class="modal fade" id="personModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-service-dialog">
        <div class="modal-content modal-service-cotain modal-content-ts">
            <div class="modal-service-body">
                <div class="m-form-item m-col-12 m-xs-12">
                    <label><b>*</b>请选择联系人模版:</label>
                    <div class="badge-lists" id="person">
                        <ul>
                           
                        </ul>
                    </div>
                </div>
            </div>
            <div class="modal-service-close">
                <i class="iconfont icon-delete_y" onclick="closePerson();"></i>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript" src="/assets/admin/js/dev/image.upload.875451.js?v={{ time() }}"></script>
<script src="https://file.wailian1.cn/admin/assets/admin/js/libs/image-conversion/conversion.js"></script>
<style type="text/css">
    .badge-lists li{
        margin: 5px!important;
    }
</style>
<script type="text/javascript">
    var but = true;
    function multiplex(){
        $.ajax({
            "url": "/admin/template/template_mini",
            "data": {},
            success: function(res){
                console.log(res);
                if (res.status == "success") {
                    if(res.data.length == 0){
                        mviewToastr("error","暂无联系人模版，请先添加联系人模版!");
                    }else if(res.data.length == 1){
                        $("#enterprise_name").val(res.data[0].enterprise_name);
                        $("#code").val(res.data[0].code);
                        $("#legal_persona_wechat").val(res.data[0].legal_persona_wechat);
                        $("#legal_persona_name").val(res.data[0].legal_persona_name);
                    }else{
                        $("#person ul").html('');
                        for(var i=0;i<res.data.length;i++){
                            var html = `<li onclick="selPerson('${res.data[i].enterprise_name}','${res.data[i].code}','${res.data[i].legal_persona_wechat}','${res.data[i].legal_persona_name}')">${res.data[i].enterprise_name}</li>`;
                            $("#person ul").append(html);
                        }
                        $("#personModal").modal('toggle');
                    }
                } else {
                    mviewToastr("error",err_text,5);
                }
            },
            error: function(err){
                mviewToastr("error","网络异常,请刷新网页后重试!");
            }
        });
    }

    function closePerson(){
        $("#personModal").modal('hide');
    }

    function selPerson(enterprise_name,code,legal_persona_wechat,legal_persona_name){
        $("#enterprise_name").val(enterprise_name);
        $("#code").val(code);
        $("#legal_persona_wechat").val(legal_persona_wechat);
        $("#legal_persona_name").val(legal_persona_name);
        $("#personModal").modal('hide');
    }

    function verifyBetaWeapp(){
        if(!but){
            mviewToastr('error','转正任务已提交,完成转正任务前不要重复提交！')
            return;
        }
        var enterprise_name = $("#enterprise_name").val();
        var code = $("#code").val();
        var legal_persona_wechat = $("#legal_persona_wechat").val();
        var legal_persona_name = $("#legal_persona_name").val();
        var legal_persona_idcard = $("#legal_persona_idcard").val();
        if(enterprise_name == ''){
            mviewToastr('error','请输入企业名称');
            return;
        }
        if(code == ''){
            mviewToastr('error','请输入企业代码');
            return;
        }
        if(legal_persona_wechat == ''){
            mviewToastr('error','请输入法人微信号');
            return;
        }
        if(legal_persona_name == ''){
            mviewToastr('error','请输入法人姓名');
            return;
        }
        if(legal_persona_idcard.length != 18){
            mviewToastr('error','请输入正确的法人身份证号');
            return;
        }
        var _token = $('meta[name="csrf-token"]').attr('content');
        var url = window.location.href;
        $.ajax({
            "url": url,
            "type":"post",
            "data": {
                enterprise_name:enterprise_name,
                code:code,
                legal_persona_wechat:legal_persona_wechat,
                legal_persona_name:legal_persona_name,
                legal_persona_idcard:legal_persona_idcard,
                code_type:1,
            },
            headers: {
                'X-CSRF-TOKEN': _token
            },
            success: function(res){
                console.log(res);
                mviewToastr(res.status,res.msg)
                if(res.status == 'success'){
                    but = false;
                }
                
            },
            error: function(err){
                mviewToastr("error","网络异常,请刷新网页后重试!");
            }
        });
    }

    function jsUploadCallBack(id,imageurl,imageName,updata,other) {
        console.log(id);
        console.log(imageurl);
        console.log(imageName);
        console.log(updata);
        console.log(other);
    }
</script>
@endsection
